const multer = require('multer');
const path = require('path');
const sc = require('silly-datetime');
const mkdirp = require('mkdirp');
function multerM(){

    const storage = multer.diskStorage({
        destination:async function (req, file, cb) {
        //自定义目录    
            //生成日期格式的目录 字符串
            let day = sc.format(new Date(),'YYMMDD');
            // 拼接
            let dir = path.join('static/upload',day)
            //生成目录  加await 必须要先生成 才让向下走； 
           await mkdirp(dir)
          cb(null, dir)
        },
        filename: function (req, file, cb) {
        //自定义文件名称    
            //生成原图片后缀 .png
          let extname = path.extname(file.originalname)
          cb(null,Date.now()+extname)
        }
      })
      
    return multer({ storage: storage })
}
module.exports = {
    multerM
}
